<template>
  <div class="page-container">
    <!--工具栏-->
    <div class="toolbar" style="float:left;padding-top:10px;padding-left:15px;">
      <el-form :inline="true" :model="filters" :size="size" ref="filters">

        <el-form-item>
          <el-popover
            placement="right"
            title="选择商家"
            trigger="click"
            width="800"
            hight="1000"
            v-model="merchantVisible">
            <el-row>
              <el-form-item  prop="pay_type"  style="float:left;padding-top:10px;padding-left:15px;">
                <el-input v-model="filtersCyTable1.merchant_code" placeholder="商家编码"></el-input>
              </el-form-item>
              <el-form-item lable="商家名称" prop="merchant_name1"  style="float:left;padding-top:10px;padding-left:15px;">
                <el-input v-model="filtersCyTable1.merchant_name1" placeholder="商家名称"></el-input>
              </el-form-item>
              <el-form-item style="float:left;padding-top:10px;padding-left:15px;">
                <kt-button icon="fa fa-search" :label="$t('action.search')" type="primary"
                           @click="resetCyTable1"/>
              </el-form-item>
              <el-form-item style="float:left;padding-top:10px;padding-left:15px;">
                <kt-button icon="fa fa-refresh" :label="$t('action.reset')"
                           @click="resetCyTable1"
                           type="primary"/>
              </el-form-item>

              <el-form-item style="float:left;padding-top:10px;padding-left:15px;">
                <kt-button icon="fa fa-hand-pointer-o" :label="$t('action.comfirm')"
                           @click="operationClick"
                           type="primary"/>
              </el-form-item>
            </el-row>

            <!--表格内容栏-->
            <cy-table1 :height="1000"
                       :data="pageResult" :columns="clickColumns"
                       @findPage="clinkMock" ref="CyTable1"
                       :showBatchDelete="false" :showDeleteOperation=false
                       :showEditOperation=false
                       :showDetailOperation=false :showOperation="false">
            </cy-table1>

            <el-input slot="reference" v-model="filters.merchant_name"
                      placeholder="商家名称" :disabled="true"></el-input>
          </el-popover>
        </el-form-item>
        <el-form-item label="对账单号" prop="reconciliation_no">
          <el-input v-model="filters.reconciliation_no" placeholder="对账单号"></el-input>
        </el-form-item>
        <el-form-item label="商家对账状态" prop="merchant_reconciliation_status">
          <el-select v-model="filters.merchant_reconciliation_status" placeholder="商家对账状态">
            <el-option label="请选择" value></el-option>
            <el-option
              v-for="item in merchantReconciliationStatusOption"
              :key="item.code"
              :label="item.label"
              :value="item.code">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="结算状态" prop="merchant_reconciliation_status">
          <el-select v-model="filters.settle_status" placeholder="结算状态">
            <el-option label="请选择" value></el-option>
            <el-option
              v-for="item in settleStatusOption"
              :key="item.code"
              :label="item.label"
              :value="item.code">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="币别名称" prop="currency_code">
          <el-select v-model="filters.currency_code" placeholder="币别名称">
            <el-option label="请选择" value></el-option>
            <el-option
              v-for="item in currencyCodeOption"
              :key="item.code"
              :label="item.label"
              :value="item.code">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="应付日期" prop="must_pay_start_date">
          <el-date-picker
            v-model="filters.must_pay_start_date"
            type="date"
            value-format="yyyy-MM-dd"
            format="yyyy-MM-dd"
            placeholder="开始" class="input_postion">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="" prop="must_pay_end_date">
          <el-date-picker
            v-model="filters.must_pay_end_date"
            type="date"
            value-format="yyyy-MM-dd"
            format="yyyy-MM-dd"
            placeholder="结束" class="input_postion">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="到账日期" prop="arrive_start_date">
          <el-date-picker
            v-model="filters.arrive_start_date"
            type="date"
            value-format="yyyy-MM-dd"
            format="yyyy-MM-dd"
            placeholder="开始" class="input_postion">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="" prop="arrive_end_date">
          <el-date-picker
            v-model="filters.arrive_end_date"
            type="date"
            value-format="yyyy-MM-dd"
            format="yyyy-MM-dd"
            placeholder="结束" class="input_postion">
          </el-date-picker>
        </el-form-item>
        <el-row>
          <el-form-item>
            <kt-button
              icon="fa fa-search"
              :label="$t('action.search')"
              type="primary"
              @click="findPage(null)"
            />
          </el-form-item>
          <el-form-item>
            <kt-button icon="fa fa-refresh" :label="$t('action.reset')" type="primary" @click="resetForm('filters')" />
          </el-form-item>
          <el-form-item>
            <kt-button
              :label="'批量对账'"
              type="primary"
              @click="batchRecon"
            />
          </el-form-item>
        </el-row>
      </el-form>
    </div>
    <div class="toolbar" style="float:right;padding-top:10px;padding-right:15px;">
      <el-form :inline="true" :size="size">
        <el-form-item>
          <el-button-group>
            <el-tooltip content="刷新" placement="top">
              <el-button icon="fa fa-refresh" @click="findPage(null)"></el-button>
            </el-tooltip>
            <el-tooltip content="列显示" placement="top">
              <el-button icon="fa fa-filter" @click="displayFilterColumnsDialog"></el-button>
            </el-tooltip>
            <el-tooltip content="导出" placement="top">
              <el-button icon="fa fa-file-excel-o" @click="downloadExcel"></el-button>
            </el-tooltip>
          </el-button-group>
        </el-form-item>
      </el-form>
      <!--表格显示列界面-->
      <table-column-filter-dialog
        ref="tableColumnFilterDialog"
        :columns="columns"
        @handleFilterColumns="handleFilterColumns"
      ></table-column-filter-dialog>
    </div>
    <!--表格内容栏-->
    <cy-table
      :width="1000"
      :height="250"
      :data="pageResult"
      :columns="filterColumns"
      :showOperation="false"
      :showEditOperation="false"
      :showBatchDelete="false"
      :showDeleteOperation="false"
      @findPage="findPage"
      ref="CyTable"
    >
    </cy-table>
  </div>
</template>

<script>
  import PopupTreeInput from "@/components/PopupTreeInput"
  import CyTable from "@/views/Core/CyTable";
  import CyTable1 from "@/views/Core/CyTable"
  import KtButton from "@/views/Core/KtButton";
  import TableColumnFilterDialog from "@/views/Core/TableColumnFilterDialog";
  export default {
    components: {
      PopupTreeInput,
      CyTable,
      CyTable1,
      KtButton,
      TableColumnFilterDialog
    },
    data() {
      return {
        size: "small",
        filters: {
          reconciliation_no: "",
          merchant_reconciliation_status: "",
          settle_status: "",
          must_pay_start_date: "",
          must_pay_end_date: "",
          arrive_start_date: "",
          arrive_end_date: "",
          currency_code: ""
        },
        settleStatusOption: [{
          code: '1',
          label: '未结算-未加入结算单'
        },{
          code: '2',
          label: '未结算-已加入结算单'
        },{
          code: '3',
          label: '已结算'
        }],
        currencyCodeOption: [{
          code: '1',
          label: 'CNY'
        },{
          code: '2',
          label: 'AUD'
        },{
          code: '3',
          label: 'GBP'
        },{
          code: '4',
          label: 'USD'
        }],
        merchantReconciliationStatusOption: [{
          code: '1',
          label: '待对账'
        },{
          code: '2',
          label: '对账成功'
        },{
          code: '3',
          label: '对账失败'
        }],
        reconciliationStatusOption:[{
          code: '1',
          label: '未结算-未加入结算单'
        },{
          code: '2',
          label: '未结算-已加入结算单'
        },{
          code: '3',
          label: '已结算'
        },{
          code: '4',
          label: '部分结算'
        }],
        radio: '1',
        options: {},
        filtersCyTable1: {
          merchant_code: "",
          merchant_name1: ""
        },
        columns: [
          { prop: "merchant_name", label: "商家名称", minWidth: 100 },
          { prop: "merchant_code", label: "供应商编码", minWidth: 100 },
          { prop: "settle_reconciliation_name", label: "供应商名称", minWidth: 100 },
          { prop: "reconciliation_no", label: "对账单号", minWidth: 100 },
          { prop: "currency_code", label: "币别", minWidth: 100 },
          { prop: "rate", label: "汇率", minWidth: 100 },
          { prop: "contract_amount", label: "合同金额", minWidth: 100 },
          { prop: "promotion_sharing_amount", label: "促销分摊金额", minWidth: 100 },
          { prop: "coupon_sharing_amount", label: "优惠卷分摊金额", minWidth: 100 },
          { prop: "must_pay_amount", label: "应付金额", minWidth: 100 },
          { prop: "expire_date", label: "到期日期", minWidth: 100 },
          { prop: "settle_status", label: "结算状态", minWidth: 100 },
          { prop: "settle_no", label: "结算单号", minWidth: 100 },
          { prop: "merchant_reconciliation_status", label: "商家对账状态", minWidth: 100 },
          { prop: "settle_date", label: "对账时间", minWidth: 100 },
          { prop: "settle_por", label: "对账人", minWidth: 100 }

        ],
        clickColumns: [
          {prop: "merchantId", label: "商家编码", minWidth: 120},
          {prop: "merchantName", label: "商家名称", minWidth: 120},
          {prop: "merchantType", label: "商家类型", minWidth: 120},
        ],
        mockPage: {
          total: "3",
          rows: [{
            id:"1",
            merchant_name: "张晓服饰",
            reconciliation_no: "DXCNY201912041911280009438561",
            settle_reconciliation_code: "1909170000040390",
            settle_reconciliation_name: "A供应商",
            currency_code: "USD",
            rate: "0.1476",
            contract_amount: "422.10",
            promotion_sharing_amount: "366.37",
            coupon_sharing_amount: "0.00",
            must_pay_amount: "55.73",
            expire_date: "2019-12-17",
            merchant_reconciliation_status: "对账成功",
            settle_status: "已结算",
            settle_no: "1911220014128375",
            settle_date: "",
            settle_por: ""
          },{
            id:"2",
            merchant_name: "张晓服饰",
            reconciliation_no: "DXCNY201912041911280009438561",
            settle_reconciliation_code: "1909170000040390",
            settle_reconciliation_name: "A供应商",
            currency_code: "USD",
            rate: "0.1476",
            contract_amount: "422.10",
            promotion_sharing_amount: "366.37",
            coupon_sharing_amount: "0.00",
            must_pay_amount: "55.73",
            expire_date: "2019-12-17",
            merchant_reconciliation_status: "对账成功",
            settle_status: "已结算",
            settle_no: "1911220014128375",
            settle_date: "",
            settle_por: ""
          },{
            id:"3",
            merchant_name: "张晓服饰",
            reconciliation_no: "DXCNY201912041911280009438561",
            settle_reconciliation_code: "1909170000040390",
            settle_reconciliation_name: "A供应商",
            currency_code: "USD",
            rate: "0.1476",
            contract_amount: "422.10",
            promotion_sharing_amount: "366.37",
            coupon_sharing_amount: "0.00",
            must_pay_amount: "55.73",
            expire_date: "2019-12-17",
            merchant_reconciliation_status: "对账成功",
            settle_status: "已结算",
            settle_no: "1911220014128375",
            settle_date: "",
            settle_por: ""
          }]
        },
        clickDetail: {
          "rows":
            [{
              "merchantId": "300001",
              "merchantName": "录屏商家二",
              "merchantType": "自营商家"
            },
              {
                "merchantId": "300001",
                "merchantName": "录屏商家二",
                "merchantType": "自营商家"
              }],
          "total": 1,
          "code": "0000"
        },

        filterColumns:[],
        pageRequest: { pageNum: 1, pageSize: 10 },
        pageResult: {},

        operation: false, // true:新增, false:编辑
        dialogVisible: false,
        detailDialogVisible: false, // 新增编辑界面是否显示
        merchantVisible: false,
        editLoading: false
      };
    },
    methods: {
      // 获取分页数据
      findPage: function(data) {
        this.$refs.CyTable.findPageMock(this.mockPage);
      },
      clinkMock: function () {
        this.$refs.CyTable1.findPageMock(this.clickDetail)
      },
      operationClick: function () {
        var this_ = this;
        this_.filters.merchant_name = "录屏商家二";
        this_.merchantVisible = false;
      },
      resetCyTable1: function () {
        this.filtersCyTable1 = {};
        this.clinkMock()
      },

      resetForm(formName) {
        if (this.$refs[formName] != undefined) {
          this.$refs[formName].resetFields();
        }
      },
// 编辑
      batchRecon: function() {
        this.$refs.CyTable.batchOperationMock("对账成功");
      },
      // 批量删除
      handleDelete: function(data) {
        var this_ = this;
        this_.$message({message: "操作成功", type: "success"});
      },
      // 处理表格列过滤显示
      displayFilterColumnsDialog: function() {
        this.$refs.tableColumnFilterDialog.setDialogVisible(true);
      },
      // 处理表格列过滤显示
      handleFilterColumns: function(data) {
        this.filterColumns = data.filterColumns;
        this.$refs.tableColumnFilterDialog.setDialogVisible(false);
      },
      // 处理表格列过滤显示
      initColumns: function() {
        var temp = [];

        $.each(this.columns, function(key, val) {
          temp.push(val);
        });
        this.filterColumns = temp;
      },
      //列表下载
      downloadExcel() {
        this.$confirm("确定下载列表文件?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
          .then(() => {
            let filename = "系统参数下载";
            this.$refs.CyTable.exportData(
              this.filters,
              this.filterColumns,
              filename
            );
          })
          .catch(() => {});
      }
    },


    mounted() {
      this.initColumns();
    }

  };
</script>

<style scoped>
</style>
